package com.whmskj.xjlhsc.controller;

import com.whmskj.xjlhsc.controller.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import com.whmskj.xjlhsc.entity.DbStatistics;
import com.whmskj.xjlhsc.service.DbStatisticsService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.GetMapping;
import java.util.List;

/**
 * 打包统计表
 *
 * @author lk
 * @since 2025-07-11 11:26:13
 */
@Api(tags = "打包统计管理")
@RestController
@RequestMapping("/api/dbStatistics")
@CrossOrigin
public class DbStatisticsController {

    @Autowired
    private DbStatisticsService dbStatisticsService;

    
    @Autowired
    private DbStatisticsService gy01VarietiesMaintenanceTableService;


    /**
     * 分页查询
     *
     * @param params
     * @return
     */
    @ApiOperation(value = "分页查询打包统计", notes = "根据条件分页查询打包统计数据")
    @PostMapping("/findPage")
    public ResponseEntity<Result> findPage(
            @ApiParam(value = "查询条件", required = false) @RequestBody(required = false) DbStatistics params) {
        Page<DbStatistics> result = dbStatisticsService.findPage(params);
        return ResponseEntity.ok(Result.success(result));
    }

    /**
     * 列表查询
     *
     * @param params
     * @return
     */
    @ApiOperation(value = "列表查询打包统计", notes = "根据条件查询打包统计数据列表")
    @PostMapping("/findList")
    public ResponseEntity<Result> findList(
            @ApiParam(value = "查询条件", required = false) @RequestBody(required = false) DbStatistics params) {
        List<DbStatistics> result = dbStatisticsService.findList(params);
        return ResponseEntity.ok(Result.success(result));
    }

    /**
     * 查询
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "根据ID查询打包统计", notes = "根据主键ID查询单条打包统计数据")
    @GetMapping("/{id}")
    public ResponseEntity<Result> findById(
            @ApiParam(value = "主键ID", required = true, example = "1") @PathVariable("id") Long id) {
        DbStatistics dbStatistics = dbStatisticsService.findById(id);
        return ResponseEntity.ok(Result.success(dbStatistics));
    }

    /**
     * 新增
     *
     * @param dbStatistics
     * @return
     */
    @ApiOperation(value = "新增打包统计", notes = "新增一条打包统计数据")
    @PostMapping
    public ResponseEntity<Result> insert(
            @ApiParam(value = "打包统计信息", required = true) @RequestBody DbStatistics dbStatistics) {
        boolean result = dbStatisticsService.insert(dbStatistics);
        return ResponseEntity.ok(Result.success(result));
    }

    /**
     * 修改
     *
     * @param dbStatistics
     * @return
     */
    @ApiOperation(value = "修改打包统计", notes = "修改打包统计数据")
    @PutMapping
    public ResponseEntity<Result> update(
            @ApiParam(value = "打包统计信息", required = true) @RequestBody DbStatistics dbStatistics) {
        boolean result = dbStatisticsService.update(dbStatistics);
        return ResponseEntity.ok(Result.success(result));
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "删除打包统计", notes = "根据主键ID删除打包统计数据")
    @DeleteMapping("/{id}")
    public ResponseEntity<Result> delete(
            @ApiParam(value = "主键ID", required = true, example = "1") @PathVariable("id") Long id) {
        int result = dbStatisticsService.delete(id);
        return ResponseEntity.ok(Result.success(result));
    }
    /**
     * 查询所有班组名称
     *
     * @return 班组名称列表
     */
    /**
     * 查询所有班组名称
     *
     * @return 班组名称列表
     */
    @ApiOperation(value = "查询所有班组名称", notes = "获取所有班组名称列表")
    @GetMapping("/classNames")
    public ResponseEntity<Result> getAllClassNames() {
        List<String> classNames = dbStatisticsService.getAllClassNames();
        return ResponseEntity.ok(Result.success(classNames));
    }

    /**
     * 查询所有品种名称
     *
     * @return 品种名称列表
     */
    @ApiOperation(value = "查询所有品种名称", notes = "获取所有品种名称列表")
    @GetMapping("/PZ/nameOfSpecies")
    public ResponseEntity<Result> getAllNameOfSpecies() {
        List<String> nameOfSpecies = gy01VarietiesMaintenanceTableService.getAllNameOfSpecies();
        return ResponseEntity.ok(Result.success(nameOfSpecies));
    }
}